package com.cdu.guoxinan.www.smartcom.controller;

import com.cdu.guoxinan.www.smartcom.domian.dto.QueryRepairManDTO;
import com.cdu.guoxinan.www.smartcom.domian.dto.UpdateRepairManDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.RepairMan;
import com.cdu.guoxinan.www.smartcom.domian.vo.SelectOption;
import com.cdu.guoxinan.www.smartcom.service.RepairManService;
import com.cdu.guoxinan.www.smartcom.unit.model.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/repairMan")
@Api(tags = "维修人员管理")
public class RepairManController {
    
    @Resource
    private RepairManService repairManService;
    
    @GetMapping("/query")
    @ApiOperation("查询维修人员列表")
    public R query(QueryRepairManDTO queryRepairManDTO) {
        return repairManService.query(queryRepairManDTO);
    }
    
    @PostMapping("/add")
    @ApiOperation("添加维修人员")
    public R add(RepairMan repairMan) {
        return repairManService.add(repairMan) ? R.ok("添加成功") : R.error("添加失败");
    }
    
    @PostMapping("/update")
    @ApiOperation("更新维修人员信息")
    public R update(UpdateRepairManDTO updateRepairManDTO) {
        return repairManService.update(updateRepairManDTO);
    }
    
    @PostMapping("/delete")
    @ApiOperation("删除维修人员")
    public R delete(@RequestParam Integer id) {
        return repairManService.delete(id) ? R.ok("删除成功") : R.error("删除失败");
    }
    
    @GetMapping("/getById")
    @ApiOperation("根据ID查询维修人员")
    public R getById(@RequestParam Integer id) {
        RepairMan repairMan = repairManService.getById(id);
        return repairMan != null ? R.ok(repairMan) : R.error("维修人员不存在");
    }

    @GetMapping("/getRepairManOptions")
    @ApiOperation("获取维修人员下拉选项")
    public R getRepairManOptions() {
        List<SelectOption> options = repairManService.getRepairManOptions();
        return R.ok(options);
    }
} 